package org.springframework.remoting.jsonrpc.test.account;


import java.util.List;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.jabsorb.JSONRPCBridge;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class AccountTestCase extends TestCase {

	ApplicationContext ctx;

	public AccountTestCase() {
		super();
	}

	public AccountTestCase(String arg0) {
		super(arg0);
	}

	public void testInsertAccount() {
		JSONRPCBridge bridge = new JSONRPCBridge();
		
		AccountService service = (AccountService) ctx.getBean("accountService");
		Account account = new Account();
		account.setName(new AccountName("account1"));
		service.insertAccount(account);
		Assert.assertTrue(true);
	}

	public void testGetAccounts() {
		AccountService service = (AccountService) ctx.getBean("accountService");
		AccountName name = new AccountName();
		name.setName("name");
		List list = service.getAccounts(name);
		Assert.assertTrue(list.size() > 0);
	}

	public void testGetAccount() {
		AccountService service = (AccountService) ctx.getBean("accountService");
		Account account = service.getAccount(new AccountId(4));
		Assert.assertTrue(account != null);
	}

	public void testGetAccountsArray() {
		AccountService service = (AccountService) ctx.getBean("accountService");
		AccountId id = new AccountId();
		Account[] accounts = service.getAccountArray(id);
		Assert.assertTrue(accounts.length > 0);
	}

	public void testAddCustomer()
	{
		AccountService service = (AccountService) ctx.getBean("accountService");
		Customer customer = new Customer();
		Account account = new Account();
		account.setName(new AccountName("account1"));
		account.setId(new AccountId(1));
		customer.setAccount(account);
		customer.setId(1);
		customer.setName("Joe Shmoe");
		service.addAccount(customer);
		Assert.assertTrue(true);
	}
	protected void setUp() throws Exception {
		super.setUp();
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
				new String[] { "/org/springframework/remoting/jsonrpc/test/accountTest.xml" });
		this.ctx = (ApplicationContext) ctx;
	}

}
